<?php

if (!isset($_FILES) || !count($_FILES)) exit();
include_once('../includes/definer.php');
include_once(INC.'php/bootstrap.php');
include_once(INC.'php/clases/FileImage.php');

$path = str_replace('admin/', '', URL).'content/images/';
$ruta = str_replace('admin/', '', INC).'content/images/';

//validaciones
$nombre = 'imagen'.'-'.time();

$ext = explode('.', $_FILES['file']['name']);
$ext = '.' . $ext[count($ext) - 1];
$ext = strtolower($ext);
$ext = ($ext == '.jpeg') ? '.jpg' : $ext;

if ($ext == '.jpg' || $ext == '.jpeg' || $ext == '.gif' || $ext == '.png') {
    //dimensionamiento y creacion de las imagenes
    $fileImage = new FileImage($_FILES['file']['tmp_name'], 85);
    if ($fileImage->ancho > 700) $fileImage->ajustarAncho(700);
    $fileImage->save($ruta.$nombre);

    //respuesta
    $response = $path.$nombre.'.'. $fileImage->extension;
}

echo($response);
